home *** CD-ROM | disk | FTP | other *** search
/ Nothing but Tetris / Nothing but Tetris.iso / amiga / wbtris_1.3 / source / statistic.c.pp / statistic.c
C/C++ Source or Header  |  2000-01-01  |  3KB  |  108 lines

  1. #include "WBTRIS.h"
  2.  
  3. #define beveloff       50
  4.  
  5.  
  6. __chip UWORD tileData[] = {
  7.     0x0080,0x7F80,0x7F80,0x7F80,0x7F80,0x7F80,0x7F80,
  8.     0xFF00,0xFF00,0xFF00,0xFF00,0xFF00,0xFF00,0x8000,
  9. };
  10.  
  11. struct Image tile = {
  12.     0, 0,
  13.     9, 7, 2,
  14.     tileData,
  15.     0x0003, 0x0000,
  16.     NULL
  17. };
  18.  
  19. extern struct TextAttr topaz8;
  20.  
  21. int StatisticField[19][4] = {
  22.         {1,1,1,1},{0,0,0,0},{0,0,1,1},{0,1,1,0},{0,0,0,0},{0,1,1,0},{0,0,1,1},{0,0,0,0},
  23.         {0,0,1,0},{0,1,1,1},{0,0,0,0},{0,1,0,0},{0,1,1,1},{0,0,0,0},{0,0,0,1},{0,1,1,1},
  24.         {0,0,0,0},{0,1,1,0},{0,1,1,0}
  25. };
  26.  
  27. void statistic(WORD WBTRIS_Window_Left, WORD WBTRIS_Window_Top, int ob1, int ob2, int ob3, int ob4, int ob5, int ob6, int ob7)
  28. {
  29.    extern APTR VisualInfo;
  30.    struct Window *win;
  31.    extern struct Screen *myscreen;
  32.  
  33.    int i;
  34.    float max=0.0;
  35.    float laenge;
  36.    float objects[7];
  37.    struct IntuiText Zeile;
  38.    char s[80];
  39.    float summe = 0;
  40.  
  41.    objects[0] = ob2;
  42.    objects[1] = ob6;
  43.    objects[2] = ob7;
  44.    objects[3] = ob3;
  45.    objects[4] = ob4;
  46.    objects[5] = ob5;
  47.    objects[6] = ob1;
  48.  
  49.    Zeile.FrontPen = 1;
  50.    Zeile.BackPen = 0;
  51.    Zeile.DrawMode = JAM2;
  52.    Zeile.LeftEdge = 0;
  53.    Zeile.TopEdge = 0;
  54.    Zeile.ITextFont = &topaz8;
  55.    Zeile.NextText = NULL;
  56.  
  57.    s[0] = '\0';
  58.  
  59.    if (win = OpenWindowTags(NULL,
  60.                             WA_Left,         WBTRIS_Window_Left,
  61.                             WA_Top,          WBTRIS_Window_Top+(myscreen->Font->ta_YSize)+3,
  62.                             WA_Width,        337,
  63.                             WA_Height,       185,
  64.                             WA_CloseGadget,  TRUE,
  65.                             WA_Title,        "<-- Click to close",
  66.                             WA_DragBar,      TRUE,
  67.                             WA_Activate,     TRUE,
  68.                             WA_IDCMP,        IDCMP_CLOSEWINDOW | WFLG_DRAGBAR
  69.                                            | IDCMP_REFRESHWINDOW | WFLG_WINDOWACTIVE,
  70.                             TAG_END)) {
  71.       DrawWin(win,VisualInfo);
  72.       for (i=0;i<7;i++) {
  73.          if (objects[i] > max)
  74.             max = objects[i];
  75.          summe = summe + objects[i];
  76.       }
  77.       if (summe == 0)
  78.          summe = 0.00000001;
  79.       if (max == 0)
  80.          max = 1;
  81.       for (i=0;i<7;i++) {
  82.          laenge = 172*objects[i]/max;
  83.          SetAPen(win->RPort,3);
  84.          RectFill(win->RPort, 47+25, 30-6+(21*i), (short)(25+47+laenge), 30+(21*i)+5);
  85.          sprintf(s, "%5.1f%%", 100*objects[i]/summe);
  86.          Zeile.IText = s;
  87.          PrintIText(win->RPort, &Zeile, 255, 30-4+(21*i));
  88.          s[0] = '\0';
  89.       }
  90.       WaitPort(win->UserPort);
  91.       CloseWindow(win);
  92.    }
  93. }
  94.  
  95.  
  96.  
  97. void DrawWin(struct Window *win,APTR  VisualInfo)
  98. {
  99.    int i,j;
  100.  
  101.    for (i=0;i<4;i++)
  102.       for (j=0;j<19;j++)
  103.          if (StatisticField[j][i] == 1)
  104.             DrawImage(win->RPort,&tile,9*i+25,7*j+30);
  105.          for (i=0;i<7;i++)
  106.             DrawBevelBox(win->RPort, 45+25 , 30-7+(i*21) , 177, 14 ,GTBB_Recessed, TRUE, GT_VisualInfo, VisualInfo);
  107. }
  108.